import time

from Common.Base import Base

register_url = 'http://172.16.11.206:8080/ecshop/user.php?act=register'


class RegisterPage(Base):
    """制作定位器"""
    username_reg = ('id', 'username')  # 用户名输入框
    username_notice_loc = ('id', 'username_notice')  # 用户名输入框提示
    email_reg = ('id', 'email')  # email输入框
    email_notice = ('id', 'email_notice')  # 邮箱输入框提示
    password_reg = ('id', 'password1')  # 密码输入框
    password_loc_notice = ('id', 'password_notice')  # 密码输入框提示
    confirm_password = ('id', 'conform_password')  # 确认密码输入框
    confirm_password_loc_notice = ('id', 'conform_password_notice')  # 确认密码输入框提示
    QQ_reg = ('name', 'extend_field2')  # QQ输入框
    office_num = ('name', 'extend_field3')  # 办公电话输入框
    family_num = ('name', 'extend_field4')  # 家庭电话输入框
    phone_num = ('name', 'extend_field5')  # 手机输入框
    password_question = ('css selector', 'select[name="sel_question"]>option:nth-of-type(10)')  # 密码问题下拉选项
    password_answer = ('name', 'passwd_answer')  # 密码问题答案输入框
    submit_acc = ('name', 'agreement')  # 接受用户协议按钮
    Submit_reg = ('name', 'Submit')  # 立即注册按钮
    user_agreement = ('link text', '用户协议')  # 用户协议链接
    want_load = ('link text', '我已有账号，我要登录')  # 我有账号,我要登录
    forget_password = ('css selector', 'a[href*="user.php?act=get_password"]')  # 忘记密码
    first_page = ('link text', '首页')  # 首页链接
    result_loc = ('class name', 'f4_b')  # 登录后用户名

    """封装操作层"""

    def input_username(self, username):
        """输入用户名"""
        self.send_keys(self.username_reg, username)

    def get_username_notice(self):
        """获取用户名提示"""
        time.sleep(6)
        return self.get_element_text(self.username_notice_loc)

    def input_email(self, email):
        """输入email"""
        self.send_keys(self.email_reg, email)

    def get_email_notice(self):
        """获取email提示"""
        time.sleep(6)
        return self.get_element_text(self.email_notice)

    def input_password(self, password):
        """
        输入密码
        :param password: 密码
        :return:
        """
        self.send_keys(self.password_reg, password)

    def get_password_notice(self):
        """获取密码提示信息"""
        time.sleep(6)
        return self.get_element_text(self.password_loc_notice)

    def conform_password(self, password):
        """
        确认密码
        :param password: 输入的确认密码
        :return:
        """
        self.send_keys(self.confirm_password, password)

    def get_conform_password_notice(self):
        """获取确认密码输入框提示信息"""
        time.sleep(6)
        return self.get_element_text(self.confirm_password_loc_notice)

    def input_QQ(self, QQ):
        """
        输入QQ号
        :param QQ: 输入的QQ
        :return:
        """
        self.send_keys(self.QQ_reg, QQ)

    def office_num_reg(self, office_num):
        """
        输入办公电话
        :param office_num: 输入的办公电话
        :return:
        """
        self.send_keys(self.office_num, office_num)

    def family_num_reg(self, family_num):
        """
        输入家庭电话
        :param family_num: 输入的家庭电话
        :return:
        """
        self.send_keys(self.family_num, family_num)

    def phone_num_reg(self, phone_num):
        """
        输入手机号
        :param phone_num: 输入的手机号
        :return:
        """
        self.send_keys(self.phone_num, phone_num)

    def password_question_reg(self):
        """
        选择密码问题
        :return:
        """
        self.click(self.password_question)

    def password_ans(self, answer):
        """
        输入密码问题答案
        :param answer: 输入的密码问题答案
        :return:
        """
        self.send_keys(self.password_answer, answer)

    def submit_accept(self):
        """
        我接受协议按钮
        :return:
        """
        self.click(self.submit_acc)

    def Submit_register(self):
        """
        立即注册按钮
        :return:
        """
        self.click(self.Submit_reg)

    def user_agree(self):
        """
        用户协议链接
        :return:
        """
        self.click(self.user_agreement)

    def want_load_reg(self):
        """
        已有账号去登录
        :return:
        """
        self.click(self.want_load)

    def forget_password_reg(self):
        """
        忘记密码
        :return:
        """
        self.click(self.forget_password)

    def first_Page(self):
        """
        首页
        :return:
        """
        self.click(self.first_page)

    def is_register_success(self, username):
        """
        判断注册是否成功,如果成功,返回TRUE,反之返回False
        @return:
        """
        return self.is_text_equal_in_element(self.result_loc, username)

    def get_register_username(self):
        """
        获取登录后的用户名
        @return:
        """
        return self.get_element_text(self.result_loc)

    def is_click_success(self, text):
        """
        判断是否链接跳转成功
        @param text: 原窗口url
        @return:
        """
        return self.is_url_equal(text)

    def is_selected(self):
        """
        判断单选框是否被选中
        @return:
        """
        return self.is_selected_submit_radio(self.submit_acc)



    def Enter(self):
        return self.Enter_keys(self.Submit_reg)

